package com.sky.mapper;

import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetMealDishMapper {

    /**
     * 根据菜品id查询对应的套餐id
     * @param dishIds
     * @return
     */
    List<Long> getSetmealIdsByDishIds(List<Long> dishIds);

    /**
     * 插入数据
     * @param setmealDish
     */
    @Insert("insert into setmeal_dish(setmeal_id, dish_id, name, price, copies) VALUES " +
            "(#{setmealId},#{dishId},#{name},#{price},#{copies})")
    void insert(SetmealDish setmealDish);

    /**
     * 批量插入数据
     * @param setmealDishes
     */
    void insertBanch(List<SetmealDish> setmealDishes);

    /**
     * 根据套餐id批量删除setmeal_dish关联数据
     * @param ids
     */
    void deleteBysetmealId(List<Long> ids);

    /**
     * 根据套餐id查询关联数据
     * @param id
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getBySetmealId(Long id);

    /**
     * 根据套餐id查询起售状态
     * @param id
     * @return
     */
    @Select("select sd.*, d.status from setmeal_dish sd " +
            "left outer join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{id}")
    List<Integer> getStatusBySetmealId(Long id);

    /**
     * 根据菜品id查询关联setmeal的起售状态
     *
     * @param id
     * @return
     */
    @Select("select d.status from setmeal_dish sd" +
            " left outer join setmeal d on sd.setmeal_id = d.id" +
            " where sd.dish_id = #{id}")
    List<Integer> getStatusByDishId(Long id);

    /**
     * 根据套餐id查询包含的菜品
     * @param setmealId
     * @return
     */
    @Select("select sd.copies, d.description,d.image,d.name from setmeal_dish sd " +
            "left outer join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItem(Long setmealId);
}
